#include "stdafx.h"
#include "InputHandler.h"
#include "InputListeners.h"
#include <windows.h>
namespace OgreModel
{
	InputHandler::InputHandler(QWidget* pWidMain,
		MouseListener *mouseListener,
		KeyboardListener *keyboardListener,
		JoystickListener *joystickListener):
		m_pWidgetMain(pWidMain),
		mLogicSystem(0),
		mMouseListener(mouseListener),
		mKeyboardListener(keyboardListener)
	{
		for (int i = VK_LBUTTON; i < VK_OEM_CLEAR + 1; ++i)
		{
			m_vEvt[i] = false;
		}
	}


	InputHandler::~InputHandler()
	{
	}

	void InputHandler::HandleEvents()
	{
		if (m_pWidgetMain->hasFocus() && m_pWidgetMain->isActiveWindow())
		{
			for (int i = VK_LBUTTON; i < VK_OEM_CLEAR + 1; ++i)
			{
				if (::GetKeyState(i) & 0x80)
				{
					m_vEvt[i] = true;
				}
				else
				{
					m_vEvt[i] = false;
				}
			}
			if (mMouseListener)
			{
				mMouseListener->VKMouseState(m_vEvt);
			}
			if (mKeyboardListener)
			{
				mKeyboardListener->VKkeyboardState(m_vEvt);
			}
		}

	}

}